<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>04.数据集合-map</title>
</head>
<body>
    
    <script>
        /* let obj = {}, obj1 = {a:1}, obj2 = {b:2};
        obj.name = '张三';
        obj[obj1] = '天空';
        obj[obj2] = '大海';
        console.log(obj);
        
        console.log(obj1.toString() === obj2.toString()); */

        // 1.创建一个Map
        let obj1 = {a:1}, obj2 = {b:2};
        const map = new Map([
            ['name','张三'],
            ['age','18'],
            ['sex','男'],
            [obj1,'今天天气很好！'],
            [obj2,'适合敲代码'],
            [[1,2,3],'hhhhhh'],
            ['name','李四'],
            ['age','20'],
        ]);
        console.log(map);

        console.log(map.size);

        // set和get
        map.set('friends',['lulu','ulul']);
        console.log(map.size);
        
        console.log(map.get('name'));
        console.log(map.get(obj1));


        // delete
        console.log(map.delete(obj1));
        console.log(map);

        // has
        console.log(map.has('name'));
        console.log(map);

        // clear
        /* map.clear() */

        // keys() values() entries()
        console.log(map.keys());
        console.log(map.values());
        console.log(map.entries());


        // 遍历
        /* map.forEach(function (value, index){
            console.log(index + ':' +value);
            
        }) */

        // 注意事项
        map.set({}, '呵呵呵呵呵呵');
        map.set({}, '哈哈哈哈哈哈');
        
        
    </script>
</body>
</html>